(function(){
	var AjaxCrud = QualityCheck.AjaxCRUD;
	var serverUrl = QualityCheck.GPUD.ServiceConfig;
	$(function(){
		var usercode = $("#user-name",parent.parent.document).attr("code");
		var userkey = $("#user-name",parent.parent.document).attr("key");
		var usertype = $("#user-name",parent.parent.document).attr("usertype");
		keyCheck(usercode,usertype,userkey,function(){
			initSmPages();
			window.onresize = function () {
				initSmPages();
			};
			initStudent();
			pagebtns();
		});
	});
	function initStudent(){
		var userkey = $("#user-name",parent.parent.document).attr("key");
		var usercode = $("#user-name",parent.parent.document).attr("code");
		var data = {
				cmd:"getStudentByUserCode",
				model:"user",
				userKey:userkey,
				data:{
					usercode:usercode
				},
				remark:""					
		};
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			if(res.result == 1 && res.data != undefined && res.data != ""){
				var content = "";
				var list = res.data;
				for(var i = 0; i < list.length; i++){
					content += "<option value='"+list[i].imei+"'>"+list[i].name+"</option>";
				}					
				$("#parent-cellphone").empty();
				$("#parent-cellphone").append(content);
			}else{
				$("#parent-cellphone").empty();
				$("#parent-cellphone").append("<option >--</option>");
			}
		},null,null);
	}	
	function pagebtns(){
		checkContents("anews-contents");
		checkContents("anotices-contents");
		$("#anews-add").click(function(){
			var content = $("#anews-contents").text();
			if(checkNews()){
				sendMessage(content);
			}
		});
		
	}
	function sendMessage(content){
		var userKey = $("#user-name",parent.parent.document).attr("key");
		var imei = $("#parent-cellphone").val();
		var data = {
				cmd:"sendTextToCard",
				model:"card",
				userKey:userKey,
				data:{
					imei:imei,
					remark:encodeURI(content),
				},
				remark:"",
		};
		processBegin("正在发布中···");
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			if(res.result == 1 && res.data != undefined && res.data != ""){
				processEnd("发布成功");
				
			}else{
				processError("发布失败");
			}
		},null,null);
	}
	function checkNews(){
		if($("#anews-contents").text() == ""){
			return false;        			
		}else{
			return true;
		}
	}
	function checkNotices(){
		if($("#anotices-contents").text() == ""){
			return false;        			
		}else{
			return true;
		}
	}
	
	
	function initSmPages(){
		var rcH = $(".body-right",parent.document).height() - $(".right-title").height()-3;
		$(".right-content").height(rcH);
		
		var cdsH = $(".right-content").height() - $(".content-title").height() - 40;
		$(".content-data-show").height(cdsH);
	}
	
})();
